/**
 * @Created by czc
 * @updated by
 * @description excel导入日志
 */
define(
	function (require, exports) {
		/**
		 * 页面加载完成时触发
		 * @param hashCode 路由ID
		 * @param data 传递数据对象
		 * @param cite 页面站点信息
		 */
		exports.ready = function (hashCode, data, cite) {
			yufp.lookup.reg('IMP_TYPE');
			yufp.lookup.reg('IMP_CHANEL');
			yufp.lookup.reg('IMP_STATUS');
			yufp.custom.vue({
				el: cite.el,
				data: function () {
					return {
						//导入导出的data  start
						tbHeight:'0',
						importFnButton: !yufp.session.checkCtrl('importFn'),
						exportFnButton: !yufp.session.checkCtrl('exportFn'),
						upLoadDialogVisible:false,//是否显示导入页面
						upLoadUrl: yufp.service.getUrl({ url: "api/file/provider/uploadfile" }),//导入的url
						appUploadDatas: [],//文件列表
						showHeader:false,//是否显示错误表头
						errshow:false,//显示导入的错误信息，默认不显示
						excelloading:false,//导入的loading
						errdata:[],//导入的错误信息
						multipleFalg:false,//是否允许多文件
						//导入导出的data  end
						
						searchFormdata: {},
						dataUrl: 'api/use/excel/queryList',
						dialogVisible: false,
						disabled:true,
						autosize:true,
						viewTitle: '导入信息汇总',
						msgContent:'',
						startDateTime: '',
						endDateTime: ''
					};
				},
				methods: {
					// 时间选择处理
					startDateTimeChange: function(value){
						this.searchFormdata.startDateTime = value;
					},
					endDateTimeChange: function(value){
						this.searchFormdata.endDateTime = value;
					},
					//点击导出模板操作
					exportDemo: function(){
						var _this = this;
						var condition = {busiType:"ALL"};
						var search = _this.searchFormdata;
						 yufp.util.download("api/use/excel/exportTempExcel?condition="
						  +  encodeURI(JSON.stringify(condition)));
					},
					download: function (cell,type){ //下载静态模板文件
						var id = cell.id;//下载的路径
						if(type == 1){//
							type = 'IMP';//导入文件
						}else if(type == 2){
							type = 'ROLLBACK';//回滚文件
						}else if(type == 3){
							type = 'SUMMARY';//导入汇总文件
						}
						var condition = {'id':id,'type':type};
						
						console.log('condition',condition);
						 yufp.util.download("api/use/excel/exportExcelLog?condition="
						  +  encodeURI(JSON.stringify(condition)));
						
						
					},
					importFlowFn: function() { //点击导入操作
						this.upLoadDialogVisible = true;
						this.$nextTick(function() {
							this.$refs['my-upload'].clearFiles();
							this.errshow = false;
							this.errdata = [];
						})
					},
					/**
					 *导入前的检验操作操作
					 */
					checkUpload: function(file) {
						//alert(file);
					
						var isLt10M = file.size / 1024 / 1024 < 100;
						if (!isLt10M) {
							this.$message.error('上传文件大小不能超过 100MB!');
						}
						var index = file.name.lastIndexOf('.');
						var ext = file.name.substr(index + 1);
					
						var suffixValid = ('xlsx' === ext || 'xls' === ext);
						if (!suffixValid) {
							this.$message.error('上传文件的格式必须为excel格式');
							return false;
						}
						return isLt10M && suffixValid;
					},
					successUpload: function(response, file, fileList) { //导入成功后执行
						/*	console.log('上传成功！')
							this.$refs['my-upload'].clearFiles();*/
					
					
						const _this = this;
						const param = {};
						/* 					_this.$loading({
												target:'.load-target',
												body:true
											}) */
						_this.excelloading = true;
						param.busiType = "ALL";
						param.excelUpLoadFile = response.data;
						yufp.service.request({
							method: 'POST',
							url: '/api/use/excel/importExcel',
							data: param,
							timeout: 1800000,
							callback: function(code, message, response) {
								_this.excelloading = false;
								if (response.code == 0 && response.data.errorInfos.length == 0 && response.data.impStatus != '失败') {
									_this.$refs['my-upload'].clearFiles();
									_this.errshow = false;
									_this.errdata = [];
									_this.upLoadDialogVisible = false;
									_this.$message('导入成功!');
									//同时重新查询列表
					
									var param = {
										condition: JSON.stringify(_this.searchFormdata)
									};
									_this.$refs.refTable.remoteData(param);
					
								} else {
									_this.errshow = true;
									_this.$refs['my-upload'].clearFiles();
									_this.errdata = [];
									if (response.data && response.data.errorInfos.length > 0 && response.data.errorInfos[0].errorList) {
										response.data.errorInfos[0].errorList.map(function(item, index) {
											_this.errdata.push({
												"errMsg": item
											})
											console.log('errdata', _this.errdata)
										})
									} else {
										_this.errdata.push({
											"errMsg": response.message
										})
									}
					
								}
							}
						});
					},
					viewFn: function(inparams){
						var _this = this;
						console.log(inparams);
						_this.dialogVisible = true;
						_this.msgContent = inparams.impReportSummary;
					}
				},
				mounted: function () {
					var _this = this;
					//测试
					_this.$nextTick(function(){
							var tableBox = _this.$refs.tableBox;
							let a = tableBox.getBoundingClientRect().top + 28;
							var theight = `calc(100vh - ${a}px - 64px)`;
							_this.tbHeight = theight;		
					});
				}
			});
		};
	});